import shutil
from moviepy.editor import *
import common.gyblog as log

LOG = log.get_logger()
PATH = '\\\\lcnas\\xishu16t2020_1\无遮挡机动车\\Caribbeancom\\{}\\'
# PATH = 'D:\workdir_2\\'
TEMP_720 = r'\\lcnas\xishu16t2020_1\temp_720\\'


def move_720(path):
    root_dirs = os.listdir(path)
    for root_dir in root_dirs:
        if root_dir[-4:] == '.mp4':
            try:
                video = VideoFileClip(path + root_dir)
                resolution_ratio = video.size
                video.close()
                print(root_dir, resolution_ratio)  # 获取分辨率
                if resolution_ratio[1] < 1080:
                    source_file = path + root_dir
                    target_file = TEMP_720 + root_dir
                    shutil.move(source_file, target_file)
                    LOG.info('移动：{}，{}'.format(source_file, target_file))
                    print('移动：{}，{}'.format(source_file, target_file))
            except:
                print("error!:{}".format(root_dir))


if __name__ == '__main__':
    year = ['2019', '2020']
    # year = ['2023', '2022', '2021', '2020', '2019', '2018']
    for y in year:
        move_720(PATH.format(y))
